<?php

	require_once MUKU_DOC_ROOT . 'lib/postData.class.php';
	
	class postDataNewsletter extends postData {
		
		protected function processData() {
			
			# check for empty fields
			if (empty($this->data['newsletter_name'])) {
				return array	(	'result'	=> FALSE,
									'message'	=> 'Kein Name angegeben!'
								);
			}
			if (empty($this->data['newsletter_email'])) {
				return array	(	'result'	=> FALSE,
									'message'	=> 'Keine Adresse angegeben!'
								);
			}
			
			# check if mail address already exists
			$sql = <<<SQL
				SELECT
					COUNT(*)
				FROM
					newsletter
				WHERE
					email = {$this->db->qstr($this->data['newsletter_email'])}
				;
SQL;
			$existCheck = (int)$this->db->GetOne($sql);
			
			if ($existCheck > 0) {
				return array	(	'result'	=> FALSE,
									'message'	=> 'Die angegebene Adresse ist bereits eingetragen!'
								);
			} else {
				# add to mailing list
				$sql = <<<SQL
					INSERT INTO
						newsletter
					SET
						`name` = {$this->db->qstr($this->data['newsletter_name'])},
						email = {$this->db->qstr($this->data['newsletter_email'])}
					;
SQL;
				$this->db->Execute($sql);
				
				return array	(	'result'	=> TRUE,
									'message'	=> 'Newsletter abonniert!'
								);
			}
			
		}
		
	}

?>
